﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ninject;
using Legazpi.Payroll.BusinessLogic.Services.Interfaces;
using Legazpi.Payroll.DataAccess.DataObjects;

namespace Legazpi.Payroll.Web.Admin.Payroll
{
    public partial class EmployeePayrollSummary : System.Web.UI.Page
    {
        [Inject]
        public IPayrollSummaryService _payrollSummaryService { get; set; }

        protected PayrollSummary Summary { get; private set; }
        
        public bool IsSuccess { get; set; }
        public bool IsError { get; set; }

        public string NotifyText { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            int empId = 0;
            int payrollId = 1;

            if (!string.IsNullOrEmpty(Request.QueryString["empid"]))            
                int.TryParse(Request.QueryString["empid"], out empId);
            
            Summary = _payrollSummaryService.GetEmployeePayrollSummary(empId, payrollId);
            
            if (!Page.IsPostBack)
                LoadDetails();
        }

        void LoadDetails()
        {
            //Personal Info
            EmployeeNameLiteral.Text = Summary.Employee.EmployeeFullname;
            PositionLiteral.Text = Summary.EmployeeDetachment.Position.Code;
            DetachMentLiteral.Text = Summary.EmployeeDetachment.Sector.Name;

            //Payroll Summary
            GrossPayLiteral.Text = Summary.GrossPay.ToString("N");
            NetPayLiteral.Text = Summary.NetPay.ToString("N");

            //Earnings Summary
            WorkHoursLiteral.Text = Summary.WorkHours.ToString("N");
            CoverUpLiteral.Text = Summary.CoverUpHours.ToString("N");
            AdjustmentLiteral.Text = Summary.GlobalAdditional.ToString("N");
            
            //Deductions Summary
            TotalDeductionLiteral.Text = Summary.TotalDeductions.ToString("N");

        }
    }
}